/*
 *   Licensed to the Apache Software Foundation (ASF) under one
 *   or more contributor license agreements.  See the NOTICE file
 *   distributed with this work for additional information
 *   regarding copyright ownership.  The ASF licenses this file
 *   to you under the Apache License, Version 2.0 (the
 *   "License"); you may not use this file except in compliance
 *   with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing,
 *   software distributed under the License is distributed on an
 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *   KIND, either express or implied.  See the License for the
 *   specific language governing permissions and limitations
 *   under the License.
 *
 */
package org.apache.directory.studio.proxy;


import org.apache.mina.core.session.IoSession;
import org.apache.mina.handler.demux.DemuxingIoHandler;


/**
 * The MINA IoHandler implementation extending {@link DemuxingIoHandler} for 
 * the LDAP protocol.
 *
 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
 */
public class LdapProtocolHandler extends DemuxingIoHandler
{
    /*
     * (non-Javadoc)
     * @see org.apache.mina.common.IoHandlerAdapter#sessionCreated(org.apache.mina.common.IoSession)
     */
    public void sessionCreated( IoSession session ) throws Exception
    {
        System.out.println( "sessionCreated" );
        super.sessionCreated( session );
    }


    /* (non-Javadoc)
     * @see org.apache.mina.core.service.IoHandlerAdapter#sessionClosed(org.apache.mina.core.session.IoSession)
     */
    public void sessionClosed( IoSession session ) throws Exception
    {
        System.out.println( "sessionClosed" );
        super.sessionClosed( session );
    }


    /*
     * (non-Javadoc)
     * @see org.apache.mina.handler.demux.DemuxingIoHandler#messageReceived(org.apache.mina.common.IoSession, java.lang.Object)
     */
    public void messageSent( IoSession session, Object message ) throws Exception
    {
        System.out.println( "messageSent" );
        // Do nothing : we have to ignore this message, otherwise we get an exception,
        // thanks to the way MINA 2 works ...
        super.messageSent( session, message );
    }


    /*
     * (non-Javadoc)
     * @see org.apache.mina.handler.demux.DemuxingIoHandler#messageReceived(org.apache.mina.common.IoSession, java.lang.Object)
     */
    public void messageReceived( IoSession session, Object message ) throws Exception
    {
        System.out.println( "messageReceived" );
        super.messageReceived( session, message );
    }


    /*
     * (non-Javadoc)
     * @see org.apache.mina.common.IoHandlerAdapter#exceptionCaught(org.apache.mina.common.IoSession, java.lang.Throwable)
     */
    public void exceptionCaught( IoSession session, Throwable cause ) throws Exception
    {
        System.out.println( "exceptionCaught:" + cause+"\nFULL MESSAGE"+cause.getMessage()+"\nSTACK TRCE" );
        cause.printStackTrace();
        super.exceptionCaught( session, cause );
    }
}